from tortoise import fields
from .base import BaseModel, TimestampMixin


class Exam(BaseModel, TimestampMixin):
    title = fields.CharField(max_length=255, description="试卷标题")
    cover = fields.CharField(max_length=255, description="封面")
    desc = fields.TextField(null=True, description="备注")
    state = fields.BooleanField(default=True, description="是否激活")
    questions = fields.JSONField(null=True, description="选项")

    class Meta:
        table = "exam_list"


class Question(BaseModel, TimestampMixin):
    exam_id = fields.IntField(default=0, description="试卷id")
    question = fields.TextField(null=True, description="问题")
    selects = fields.JSONField(null=True, description="选项")
    answer = fields.JSONField(null=True, description="答案")

    class Meta:
        table = "exam_question"


class Result(BaseModel, TimestampMixin):
    exam_id = fields.IntField(default=0, description="试卷id")
    name = fields.CharField(max_length=255, description="名称")
    rate = fields.CharField(max_length=255, description="比例")
    score_min = fields.IntField(default=0, description="分数区间最小值")
    score_max = fields.IntField(default=100, description="分数区间最大值")
    url_type = fields.IntField(default=0, description="跳转类型")
    url = fields.CharField(max_length=255, description="跳转地址")
    picture = fields.JSONField(null=True, description="图片地址")

    class Meta:
        table = "exam_result"


class UserAnswer(BaseModel, TimestampMixin):
    user_id = fields.IntField(default=0, description="用户id")
    exam_id = fields.IntField(default=0, description="试卷id")
    user_answer = fields.JSONField(null=True, description="用户答案")
    user_score = fields.IntField(default=0, description="用户得分")
    result_name = fields.CharField(max_length=255, description="结果名称")

    class Meta:
        table = "exam_answer"
